<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class SingleLogin
{
  public function handle(Request $request, Closure $next)
  {
    $token = $request->bearerToken();
    $uid = auth()->id();
    $cached = \Cache::get("user:{$uid}:token", $token);
    if ($token !== $cached) {
      forbidden();
      return;
    }
    return $next($request);
  }
}
